import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';

///进度状态管理
class ProgressNotifier extends ChangeNotifier {
  double _progress = 0.0;

  double get progress => _progress;

  void updateProgress(double value) {
    _progress = value;
    notifyListeners();
  }
}

///外设蓝牙状态管理
class DeviceConnectStateNotifier extends ChangeNotifier {
  BluetoothDevice? _connectedDevice;

  BluetoothDevice? get connectedDevice => _connectedDevice;

  void setConnectedDevice(BluetoothDevice? device) {
    try {
      _connectedDevice = device;
      notifyListeners();
    } catch (e) {
      // Handle the connection error
      print('Connection failed: ======$e');
    }
  }
}

///log状态管理
class LogNotifier extends ChangeNotifier {
  List<String> _logs = [];

  List<String> get logs => _logs;

  void newLog(String text) {
    try {
      _logs.add(text);
      notifyListeners();
    } catch (e) {
      // Handle the connection error
      print('Connection failed: ======$e');
    }
  }

  void clear() {
    try {
      _logs.clear();
      notifyListeners();
    } catch (e) {
      // Handle the connection error
      print('Connection failed: ======$e');
    }
  }
}
